{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Regressão Linear Simples - Trabalho\n",
    "\n",
    "## Estudo de caso: Seguro de automóvel sueco\n",
    "\n",
    "Agora, sabemos como implementar um modelo de regressão linear simples. Vamos aplicá-lo ao conjunto de dados do seguro de automóveis sueco. Esta seção assume que você baixou o conjunto de dados para o arquivo insurance.csv, o qual está disponível no notebook respectivo.\n",
    "\n",
    "O conjunto de dados envolve a previsão do pagamento total de todas as reclamações em milhares de Kronor sueco, dado o número total de reclamações. É um dataset composto por 63 observações com 1 variável de entrada e 1 variável de saída. Os nomes das variáveis são os seguintes:\n",
    "\n",
    "1. Número de reivindicações.\n",
    "2. Pagamento total para todas as reclamações em milhares de Kronor sueco.\n",
    "\n",
    "Voce deve adicionar algumas funções acessórias à regressão linear simples. Especificamente, uma função para carregar o arquivo CSV chamado *load_csv ()*, uma função para converter um conjunto de dados carregado para números chamado *str_column_to_float ()*, uma função para avaliar um algoritmo usando um conjunto de treino e teste chamado *split_train_split ()*, a função para calcular RMSE chamado *rmse_metric ()* e uma função para avaliar um algoritmo chamado *evaluate_algorithm()*.\n",
    "\n",
    "Utilize um conjunto de dados de treinamento de 60% dos dados para preparar o modelo. As previsões devem ser feitas nos restantes 40%. \n",
    "\n",
    "Compare a performabce do seu algoritmo com o algoritmo baseline, o qual utiliza a média dos pagamentos realizados para realizar a predição ( a média é 72,251 mil Kronor).\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Aluno: Marcos Felipe de Menezes Mota - 354080"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Calculate the mean value of a list of numbers\n",
    "def mean(values):\n",
    "  return sum(values) / float(len(values))\n",
    "\n",
    "\n",
    "# Calculate the variance of a list of numbers\n",
    "def variance(values, mean):\n",
    "  return sum([(x-mean)**2 for x in values])\n",
    "\n",
    "\n",
    "# Calculate covariance between x and y\n",
    "def covariance(x, mean_x, y, mean_y):\n",
    "  covar = 0.0\n",
    "  for i in range(len(x)):\n",
    "    covar += (x[i] - mean_x) * (y[i] - mean_y)\n",
    "  return covar\n",
    "\n",
    "\n",
    "# Calculate coefficients\n",
    "def coefficients(dataset):\n",
    "      x = [row[0] for row in dataset]\n",
    "      y = [row[1] for row in dataset]\n",
    "      x_mean, y_mean = mean(x), mean(y)\n",
    "      b1 = covariance(x, x_mean, y, y_mean) / variance(x, x_mean)\n",
    "      b0 = y_mean - b1 * x_mean\n",
    "      return [b0, b1]\n",
    "\n",
    "\n",
    "def simple_linear_regression(train, test):\n",
    "  predictions = list()\n",
    "  b0, b1 = coefficients(train)\n",
    "  for row in test:\n",
    "    ypred = b0 + b1 * row[0]\n",
    "    predictions.append(ypred)\n",
    "  return predictions\n",
    "\n",
    "from math import sqrt\n",
    "\n",
    "# Calculate root mean squared error\n",
    "def rmse_metric(actual, predicted):\n",
    "  sum_error = 0.0\n",
    "  for i in range(len(actual)):\n",
    "    prediction_error = predicted[i] - actual[i]\n",
    "    sum_error += (prediction_error ** 2)\n",
    "  mean_error = sum_error / float(len(actual))\n",
    "  return sqrt(mean_error)\n",
    "\n",
    "# Evaluate regression algorithm on training dataset\n",
    "def evaluate_algorithm(dataset, algorithm):\n",
    "  test_set = list()\n",
    "  for row in dataset:\n",
    "    row_copy = list(row)\n",
    "    row_copy[-1] = None\n",
    "    test_set.append(row_copy)\n",
    "  predicted = algorithm(dataset, test_set)\n",
    "  print(predicted)\n",
    "  actual = [row[-1] for row in dataset]\n",
    "  rmse = rmse_metric(actual, predicted)\n",
    "  return rmse\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "dataset = pd.read_csv(\"insurance.csv\")\n",
    "dataset = dataset.iloc[:, :].values\n",
    "# y = dataset.iloc[:, -1].values\n",
    "data_train, data_test = train_test_split(dataset, test_size=0.4, random_state=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19.6507219828 3.58141779557\n"
     ]
    }
   ],
   "source": [
    "data_train = data_train\n",
    "data_test = data_test\n",
    "b0, b1 =  coefficients(data_train)\n",
    "print(b0, b1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f1745bd4320>,\n",
       " <matplotlib.lines.Line2D at 0x7f1745bd4be0>]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAF6pJREFUeJzt3X+MHGd9x/HP147t5gjFwT6jEMd7\nUCJUhFRIzigVVcUlpEpp1aQSBNNTcaVIVzlBIuIPE2KdS+2eSqw2QaiV1aNBDb0rYAFtDE1FA96I\nIrXpnSGEhAhiIttxEsVG+UHhgCr2t3/MbH133rvbmZudeeaZ90s67c6zs7vP3O5+9tlnnnnG3F0A\ngHitqboCAID+IugBIHIEPQBEjqAHgMgR9AAQOYIeACJH0ANA5Ah6AIgcQQ8Akbuo6gpI0ubNm31o\naKjqagBArRw9evTH7j640npBBP3Q0JBmZ2errgYA1IqZnehlPbpuACByBD0ARI6gB4DIEfQAEDmC\nHgAiR9CjMAcOSO32wrJ2OykHUB2CHoXZvl26+ebzYd9uJ8vbt1dbL6Dp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q0In79zWydkpCbdvcvp8WNee27bX/W17/OQT8j6Uoze4OZrZe0Q9Lh\niutUCjN7VbpjRmb2Kkm/I+mx5e8VpcOSdqbXd0q6v8K6lKoTcqk/VKSvv5mZpHslPeHud8+7qRGv\n/VLbn/X1r+2oG0lKhxR9UufPTTtRcZVKYWZvVNKKl5LTQf5T7NtuZp+T9C4lM/c9L+nPJP2LpEOS\ntkk6Kel97h7dTssltv1dSn62u6Tjkv6002cdEzP7LUn/Iel7ks6lxXcq6aduwmu/1PZ/QBle/1oH\nPQBgZXXuugEA9ICgB4DIEfQAEDmCHgAiR9ADQOQIegCIHEEPAJEj6AEgcv8H3hUrwGEKiiUAAAAA\nSUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f1745334668>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "predicted = simple_linear_regression(data_train, data_test)\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(predicted, 'bx')\n",
    "ax.plot(data_test, 'ro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[84.827199877560176, 64.419036530123094, 441.97005845770917, 156.25577159358997, 214.07890107799506, 98.432642109184897, 67.820397088029267, 173.26257438312089, 54.214954856404539, 37.208152066873637, 183.46665605683944, 57.616315414310719, 98.432642109184897, 44.010873182685998, 27.004070393155089, 101.83400266709108, 40.609512624779818, 30.405430951061273, 98.432642109184897, 40.609512624779818, 50.813594298498359, 50.813594298498359, 30.405430951061273, 118.84080545662198, 44.010873182685998, 33.80679150896745, 88.228560435466349, 44.010873182685998, 33.80679150896745, 20.201349277342729, 105.23536322499726, 40.609512624779818, 37.208152066873637, 95.03128155127871, 57.616315414310719, 227.68434330961978, 61.017675972216907, 33.80679150896745, 74.623118203841628, 64.419036530123094, 224.2829827517136, 159.65713215149617, 146.05168991987142, 207.27617996218268, 159.65713215149617, 57.616315414310719, 112.03808434080962, 47.412233740592178, 30.405430951061273, 78.024478761747815, 64.419036530123094, 64.419036530123094, 71.22175764593544, 47.412233740592178, 118.84080545662198, 122.24216601452817, 101.83400266709108, 50.813594298498359, 125.64352657243434, 67.820397088029267, 200.47345884637033, 108.63672378290345]\n",
      "rmse: 35.645626526620674\n"
     ]
    }
   ],
   "source": [
    "rmse = evaluate_algorithm(dataset, simple_linear_regression)\n",
    "print(\"rmse:\", rmse)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
